<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="../../../../common/common.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link href="${ctx}/static/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
    <link href="${ctx}/static/dist/css/font-awesome.min.css" rel="stylesheet" type="text/css"/>
    <link href="${ctx}/static/plugins/datatables/css/matrix-style.css" rel="stylesheet" type="text/css"/>
    <link href="${ctx}/static/dist/css/AdminLTE.css" rel="stylesheet" type="text/css"/>
    <link href="${ctx}/static/plugins/datatables/css/dataTables.bootstrap.css" rel="stylesheet" type="text/css"/>
    <link href="${ctx}/static/plugins/validationEngine/css/validationEngine.jquery.css" rel="stylesheet"
          type="text/css">
    <link href="${ctx}/static/plugins/layer/skin/default/layer.css" rel="stylesheet" type="text/css"/>
    <style type="text/css">
        .btn-sm {
            border-width: 4px;
            font-size: 13px;
            padding: 4px 9px;
            line-height: 1.39;
        }

        .code_space {
            margin-left: -4px;
            margin-right: 14px;
        }

        .btn_key {
            background-color: #6fb3e0 !important;
            border-color: #6fb3e0;
        }

        .btn_key:hover {
            color: #fff;
            background-color: #39b3d7;
            border-color: #269abc;
        }

        .code_width {
            width: 36.5%;
        }

        @media only screen and (max-width: 767px ) {
            .code_width {
                width: 102%;
            }
        }

        .radios {
            margin-bottom: 20px;
            float: left;
            margin-left: 40px;
        }
        .left{
        	float:left; width:44%; height:100%; 
        }
        .right{
        	float:left; width:56%;height:100%; 
        }
        .form-control{
        	width:250px;
        }
		.image-control{
			width: 200px;
			height: 100px;
			border: solid thin seashell;
			background-color: gainsboro;
		}
    </style>
</head>
<body>

<div class="content">
	
    <form class="form-horizontal" id="addForm">
	    <br>
		<br>
		<br>
		<br>
        <div class="all" style="float:inherit;margin-top: -30px">
			<div class="left">
				<div class="form-group" style="display:none;">
		            <label for="manageId" class="col-sm-4 control-label">用户Id和当天已经提现的金额:</label>
		            <div class="col-sm-3">
		             	<input type="text" class="form-control" id="manageId" name="manageId"
	                     value="${userBalanceVo.manageId}">
		             	<input type="text" class="form-control" id="balance" name="balance"
	                     value="${userBalanceVo.balance}">
		             	<input type="text" class="form-control" id="drawcashStatusPendingTotal" name="drawcashStatusPendingTotal"
	                     value="${userBalanceVo.drawcashStatusPendingTotal}">>
		            </div>
		        </div>
		        <div id="inputShow" class="form-group">
		            <label for="drawcashMoney" class="col-sm-4 control-label"><span style="color:red;">*</span>提现金额:</label>
		            <div class="col-sm-3">
		                <input type="text" class="form-control validate[required,custom[number],min[100],max[10000]]" id="drawcashMoney" name="drawcashMoney"
		                     data-fun="dataFunDemo" placeholder="可申请提现余额${userBalanceVo.canApplyDrawcashMoney}元">
		            </div>
		        </div>
				<div class="form-group" align="center">
					<div class="col-sm-10">
		               <span>今日剩余可提现额度${userBalanceVo.drawcashMoneyToday}元，每日提现限额100-10000元</span>
		            </div>
		        </div>
				<div class="form-group" align="center">
		            <div class="col-sm-10">
		                <button type="button" id="drawcashBtn" onclick="" class="btn btn-primary">提现申请</button>
		            </div>
        		</div>
	       </div>
       </div>
    </form>
</div>
<script src="${ctx}/static/plugins/jQuery/jQuery-2.1.4.min.js"></script>
<script src="${ctx}/static/bootstrap/js/bootstrap.min.js"></script>
<!-- datatable -->
<script src="${ctx}/static/plugins/datatables/jquery.dataTables.js" type="text/javascript"></script>
<script src="${ctx}/static/plugins/datatables/dataTables.bootstrap.js" type="text/javascript"></script>
<script src="${ctx}/static/js/common/time/WdatePicker.js" type="text/javascript"></script>
<script src="${ctx}/static/plugins/validationEngine/jquery.validationEngine-zh_CN.js"></script>
<script src="${ctx}/static/plugins/validationEngine/jquery.validationEngine.js"></script>
<script src="${ctx}/static/plugins/layer/layer.js"></script>
<script>

    $(function () {
		
    	$("#addForm").validationEngine({ 
    		promptPosition: "topRight", 
    		validationEventTriggers:"keyup blur", 
    		success :  false,
    		failure : function() { callFailFunction()  }
   		});
    	
    	$("#successShow").hide();
    	$("#drawcashBtn").click(function(){
    		
    		//1.表单验证
	    	var flag = $("#addForm").validationEngine("validate");
	    	if(!flag){
	     		return false;
	    	}
	    	//2.验证一次提现金额不超过余额
	    	if(new Number(${userBalanceVo.balance})-new Number($("#drawcashMoney").val())<0){
	    		alert("提现金额超过了您的余额${userBalanceVo.balance}元！");
	    		return;
	    	}
	    	//3.验证已申请提现金额总和不超过余额
	    	var drawcashMoneyCompareBanlance = new Number(${userBalanceVo.drawcashStatusPendingTotal})+new Number($("#drawcashMoney").val());
	    	if(${userBalanceVo.balance}-drawcashMoneyCompareBanlance<0){
	    		alert("可申请提现余额为"+${userBalanceVo.canApplyDrawcashMoney}+"元！");
	    		return;
	    	}
	    	//4.验证当天提现的金额总和不超过10000
	    	var drawcashMoneyCompare10000 = new Number(10000-${userBalanceVo.drawcashMoneyToday})+new Number($("#drawcashMoney").val());
	    	if(drawcashMoneyCompare10000-10000>0){
	    		alert("今日剩余可提现金额"+${userBalanceVo.drawcashMoneyToday}+"元,当天申请提现总金额不能超过10000元！");
	    		return;
	    	}
	    	
            if (confirm("确认申请提现?") == true) {
	    		//提交数据
	        	$.ajax({
	        		async       : false,
	        		type 		: "POST",
	        	    url		    : "${ctx}/api/agent/drawcashAgent",
	        		data 		: $("#addForm").serialize(),
	        		success 	: function( d ) {
	        			if(d.code=="200"){
	        				alert("已提交提现申请!");
	        		        window.location.href = "${ctx}/api/agent/agentBalancePage?manageId=${userBalanceVo.manageId}";
	        			} else {
	        				alert(d.message);
	        			}
	        		}
	        	});
            } else {
                return false;
            }
    	});
    });


</script>
</body>
</html>